M.remoteStaticPathEnable = false;


formformat = {
    "api": [
        {
            "key": "id",
            "note": "id",
            "value": "1",
            "dateFormat": {
                "dateType": "String"
            }
        },
        {
            "key": "username",
            "note": "用户名",
            "value": "zs",
            "dateFormat": {
                "dateType": "String",
                "required":false
            }
        }

    ]
}

app.get("/api/getFormformat", (req, res) => {
    res.send(M.result(formformat))
})



app.post("/api/add", (req, res) => {
    r = M.add(JSON.parse(req.body));
    res.send(M.result(r));
});

app.get("/api/delete", (req, res) => {
    M.deleteById(req.params.id);
    res.send(M.result("ok"));
});

app.post("/api/update", (req, res) => {
    r = M.update(JSON.parse(req.body));
    res.send(M.result("ok"));
});

app.get("/api/getById", (req, res) => {
    r = M.getById(req.params.id);
    res.send(M.result(r));
});

app.get("/api/listAll", (req, res) => {
    r = M.listAll();
    res.send(M.result(r));
});

app.get("/api/listByParentId", (req, res) => {
    r = M.listByProp({ parentId: req.params.parentId });
    res.send(M.result(r));
});

app.get("/api/listByPage", (req, res) => {
    let r;
    if(req.params.name){
        r = M.listByPage(req.params.startPage, req.params.limit,{username:req.params.name});
    }else{
        r = M.listByPage(req.params.startPage, req.params.limit);
    }
    res.send(M.result(r));
})